var express = require('express');
var fs = require('fs');
var router = express.Router();
var multer = require('multer');
var upload = multer({ dest: 'public/images/shopping-pic/' })

router.post('/', upload.single('img'), function (req, res, next) {
    let type = ['express-pic', 'shopping-pic', 'other-pic']
    let typeIndex = req.body.type
    let file = req.file
    fs.renameSync(file.path, `public/images/${type[typeIndex]}/` + file.originalname)
    // res.json({ data: `http://localhost:3000/images/${type[typeIndex]}/${file.originalname}`, code: 200, msg: 'uploaded!' })
    res.send(`http://localhost:3000/images/${type[typeIndex]}/${file.originalname}`)
})

module.exports = router;
